/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.FocusListener;
import com.sun.lwuit.layouts.BoxLayout;
import core.ScreenEngine;
import core.Settings;
import view.additional.VolumeSetter;
import view.commands.BackCommand;

/**
 *
 * @author Kvest
 */
public class VolumeSettingsForm extends BasicForm
{
    private static final int ACCEPT_COMMAND_ID = 1;
    
    private VolumeSetter volume;
    
    public VolumeSettingsForm()
    {
        super("volume");
        
        init();
    }
    
    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        setCyclicFocus(false);

        addComponent(new Label("volume"));
        volume = new VolumeSetter();
        addFocusListener(new FocusListener() 
        {
            public void focusGained(Component cmpnt) 
            {
                if (cmpnt == volume)
                {             
                    volume.fireClicked();
                }
            }

            public void focusLost(Component cmpnt){}
        });
        addComponent(volume);
        
        //Команды
        addCommand(new BackCommand());
        
        Command accept = new Command("accept", ACCEPT_COMMAND_ID)
        {
            public void actionPerformed(ActionEvent evt)
            {   
                Settings.getSettings().setVolume(volume.getProgress());
                 
                ScreenEngine.getEngine().popTo(0);
                
                evt.consume();
            }
        };
        addCommand(accept);
    }
    
    public void show()
    {
        setContent();
        
        super.show();
    }
    
    private void setContent()
    {
        volume.setProgress(Settings.getSettings().getVolume());
    }
}
